<div id="admin" style="width: 100%;height: 100%;">
						
					 <script type="text/javascript" src="../../wangEditor/release/wangEditor.min.js"></script>
					 <script type="text/javascript" src="../../wangEditor/release/qiniu.js"></script>
					 <script type="text/javascript" src="../../wangEditor/release/plupload.full.min.js"></script>
				    <script type="text/javascript">
				        var E = window.wangEditor
				        var editor = new E('#editor')
				        editor.customConfig.uploadImgShowBase64 = true
				        //editor.customConfig.qiniu = true
				        // 或者 var editor = new E( document.getElementById('#editor') )
				     // 配置服务器端地址
				        editor.customConfig.uploadImgServer = '/News/uploadIMg.do'
				        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
				        editor.customConfig.uploadImgMaxLength = 10
				        editor.create()
				        
	  // 初始化七牛上传
	//	uploadInit()
		
		// 初始化七牛上传的方法
		
				    </script>	
					<div class="panel panel-default">
						<div class="panel-heading">
							管理员列表
						</div>

						<div class="navbar-form navbar-left" role="search">
							<div class="form-group">
								<input type="text" id="newsTitle" class="form-control" placeholder="请输入咨询标题">
							</div>
							 <button type="button" onclick="ready('','');" style="" class="btn btn-default">搜索</button>
                             <button onclick="addAdminT();" class="btn btn-success" id="btn_add" data-toggle="modal"><i class="glyphicon glyphicon-plus"></i>&nbsp;新增</button>
						</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<div class="table-responsive" style="height:600px;">
								<table class="table">
									<thead>
										<tr>
											<th>#</th>
											<th>咨讯标题</th>
											<th>咨讯内容</th>
											<th>创建时间</th>
											<th>管理名称</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="admin_tbody">
									
									</tbody>
								</table>
							</div>
							<!-- /.table-responsive -->
						</div>
						<!-- /.panel-body -->
					</div>

					 <div style="text-align:right">
	                    <span style="margin-right:30px;">当前是：01页</span>
	                    <ul class="pagination pagination-sm" id="paging" style="vertical-align:middle;">
						<li><a href="#">&laquo;</a></li>
						<li><a href="#">1</a></li>
						<li><a href="#">2</a></li>
						<li><a href="#">3</a></li>
						<li><a href="#">4</a></li>
						<li><a href="#">5</a></li>
						<li><a href="#">&raquo;</a></li>
				       </ul>
                    </div>
					
					
					
					
					<div class='pop' id="pop">
						<div class='box'>
							<div class="modal-header">
									添加任务
									<button type="button" onclick="closeWindow();" class="close" data-dismiss="modal" aria-hidden="true">×</button>
									<h4 class="modal-title" id="myModalLabel"></h4>
								</div>
								<div>
										<div class="form-group pad0-30" align="center">
											<label for="firstname" >咨讯标题</label>
											<input type="text" class="form-control" id="newsTitle1" placeholder="请输入咨讯标题"><span id="newsTitleErr" style="color: red"></span>
										</div>
										<input type="hidden" class="form-control" id="admin_id" placeholder="请输入咨讯标题">
										<input type="hidden" class="form-control" id="nid" placeholder="请输入咨讯标题">
										<div class="form-group pad0-30" align="center">
											<label for="lastname" >咨讯内容</label>
												 <div id="editor" style="text-align: left;">
												 
											    </div>
											     
											<!-- <textarea rows="5" cols="10" id="newsText" style="margin: 0px; width: 453px; height: 112px;">
											
											</textarea> -->     
											     
										</div>
									<div align="center" id="errInput" style="color: red;"></div>
								</div>
								<div class="modal-footer">
									<button id="closeW" type="button" class="btn btn-default" onclick="closeWindow();">关闭</button>
									<button type="button" id="submit" onclick="addAdmin();" class="btn btn-primary">提交</button>
								</div>
							</div>
							
						</div>
					</div>
					

<script type="text/javascript">
	
	
	//页面加载执行数据渲染	
	$(function(){ 
		ready("","");
	}); 
	
	
	//界面加载方法
	function ready(currentPageNum,totle){
		
		// 分页参数设定
		if(currentPageNum=="" || currentPageNum==null){
			currentPageNum=1;
		}
		
		// 分页参数设定
		if(totle=="" || totle==null){
			totle=10;
		}
		var newsTitle=$("#newsTitle").val();
		
		var data={'currentPageNum':currentPageNum,'perPageSize':totle,'newsTitle':newsTitle};
		
		$.ajax({  
		    type:'post',    
		    url:'/News/selectByAll.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){ 
				console.log(data);		    	
		    	Data_assembly(data);
		    	footer(data.data.totalPageNum,data.data.currentPageNum);
		    }  
		  });
	}
	
	//数据组装方法
	function Data_assembly(data){
		  console.log(data);
		  console.log(tbody);
		  var tbody=data.data.entitys;
		  var html="";
		  var b=1;
		  for(var i=0;i<tbody.length;i++){
			  html+='<tr>';
			  html+='<td>'+b+'</td>';
			  html+='<td>'+tbody[i].newsTitle+'</td>';
			  if(tbody[i].newsText.length>20){
				  html+='<td>'+ tbody[i].newsText.substring(0,10)+'...</td>';
			  }else{
				  html+='<td>'+ tbody[i].newsText+'</td>';
			  }
			 
			  html+='<td>'+tbody[i].createtime+'</td>';
			 html+='<td>'+tbody[i].andminName+'</td>';
			  html+='<td><button type="button" onclick="updateNewsFind('+"'"+tbody[i].id+"'"+');" class="btn btn-warning">修改</button>&nbsp;&nbsp;'
				  +'<button type="button" onclick="deleteNew('+"'"+tbody[i].id+"'"+');" class="btn btn-danger">删除</button></td>';
			  html+='</tr>';
			  b++;
		  }
		  
		  $("#admin_tbody").html(html);
	}
	
	//修改前查询
	function updateNewsFind(id){
		$("#submit").attr("onclick",""); 
		$("#submit").attr("onclick","updateNews()"); 
		var data={'id':id};
		$.ajax({  
		    type:'post',    
		    url:'/News/selectByAll.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){  
		    	 var tbody=data.data.entitys;
		    	 console.log(tbody);
		    	 $("#newsTitle1").val(tbody[0].newsTitle);
		    	 var newsText=editor.txt.html(tbody[0].newsText);
	    		 $("#admin_id").val(tbody[0].adminId);
	    		 $("#nid").val(tbody[0].id);
			     closeWindow();
		
		    }
		});
	}
	
	
	function updateNews(){
		var newsTitle=$("#newsTitle1").val();
		var newsText=editor.txt.html();
		var id=$("#nid").val();
		var adminId=$("#admin_id").val();
		var errText="";
		var errCode="0";
		
		
		if(id==null || id==''){
			alert("系统错误,修改失败");
			return;
		}
		if(adminId==null || adminId==''){
			alert("系统错误,修改失败");
			return;
		}
		//数据校验
		if(newsTitle==null || newsTitle=='' || newsTitle.length>20){
			  $("#newsTitleErr").html("标题不能为空,且长度不能超过十个字段");
			  errCode="1";
		}else{
			 $("#newsTitleErr").html("");
		}
		
		//数据校验
		if(newsText==null || newsText=='' || newsText.length>2000){
			  $("#newsTextErr").html("资讯内容不能为空,且长度不能超过二千个字段");
			  errCode="1";
		}else{
			 $("#newsTextErr").html("");
		}
		
		if(errCode=="1"){
			return;
		}
				
		var data={'newsTitle':newsTitle,'newsText':newsText,'id':id,'adminId':adminId};	
		$.ajax({  
		    type:'post',    
		    url:'/News/updateNews.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){  
		    	alert(data.msg);
		    	ready("","");
		    	closeWindow();
		    	
		    }  
		  });
		
	}
	
	//打开添加的窗口
	function addAdminT(){
		$("#newsTitle1").val("");
		var newsText=editor.txt.html('');
		$("#submit").attr("onclick",""); 
		$("#submit").attr("onclick","addAdmin()"); 
		closeWindow();
	}
	
	//添加
	function addAdmin(){
		var newsTitle=$("#newsTitle1").val();
		var newsText=editor.txt.html();
		var txt=newsText.replace(/<\/?(img|a)[^>]*>/gi, '');
		var errText="";
		var errCode="0";
		//数据校验
		if(newsTitle==null || newsTitle=='' || newsTitle.length>20){
			  $("#newsTitleErr").html("标题不能为空,且长度不能超过十个字段");
			  errCode="1";
		}else{
			 $("#newsTitleErr").html("");
		}
		
		//数据校验
		if(txt==null || txt=='' || txt.length>2000){
			  $("#newsTextErr").html("资讯内容不能为空,且长度不能超过二千个字段");
			  errCode="1";
		}else{
			 $("#newsTextErr").html("");
		}
		
		if(errCode=="1"){
			return;
		}
				
		var data={'newsTitle':newsTitle,'newsText':newsText};	
		$.ajax({  
		    type:'post',    
		    url:'/News/insertNews.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){  
		    	alert(data.msg);
		    	ready("","");
		    	closeWindow();
		    	
		    }  
		  });
	
	}
	
	//删除
	function deleteNew(id){
		if(id==null || id==''){
			return;
		}
		var data={'id':id};
		$.ajax({  
		    type:'post',    
		    url:'/News/deleteNews.do',  
		    data:data,  
		    cache:false,  
		    dataType:'json',  
		    success:function(data){  
		    	alert(data.msg);
		    	ready("","");
		    }  
		  });
	}
	
	
	//关闭弹出层
	function closeWindow(){
		$("#pop").fadeToggle();
	}
	
	
	//分页页脚生成方法
	//dataSize 总页数
	//unmSize 当前所在页数
	function footer(dataSize, unmSize) {
		$("#paging").find("li").remove();
		var html = '<li><a href="javascript:skip(1,' + unmSize + ',' + dataSize
				+ ');">&laquo;</a></li>';
		$("#paging").append(html);

		var number = 12;

		// 判断生成前面部分页脚
		if (unmSize > 5) {
			html = '<li><a href="javascript:skip(0,1);">1</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:skip(0,2);">2</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:void(0);">...</a></li>';
			$("#paging").append(html);
			number = number - 3;
			// 循环生成前半部分
			for (var i = 3; i > 0; i--) {
				if (unmSize - 2 - i > 3) {
					for (i; i > 0; i--) {
						number--;
						var finlSize = unmSize;
						finlSize = finlSize - i;
						html = '<li><a href="javascript:skip(0,' + finlSize + ','
								+ dataSize + ');">' + finlSize + '</a></li>';
						$("#paging").append(html);
					}
					break;
				}
			}

		} else {
			for (var i = 1; i < unmSize; i++) {
				number--;
				html = '<li><a href="javascript:skip(0,' + i + ',' + dataSize
						+ ');">' + i + '</a></li>';
				$("#paging").append(html);
			}
		}

		// 生成当前页
		html = '<li><a style="color:#000;" href="javascript:skip(0,' + unmSize
				+ ',' + dataSize + ');">' + unmSize + '</a></li>';
		$("#paging").append(html);

		// 循环生成后半部分
		for (var i = number; i > 0; i--) {

			if (unmSize + i <= dataSize) {
				number = i;
				var size = unmSize;
				for (i; i > 0; i--) {
					size = size + 1;
					html = '<li><a href="javascript:skip(0,' + size + ','
							+ dataSize + ');">' + size + '</a></li>';
					$("#paging").append(html);
				}
			}
		}
		
		
		// 判断生成最后部分页脚
		var endNumber = dataSize - unmSize - number;
		if (endNumber > 3) {
			// 尾部长度超出三个，用省略号代替
			html = '<li><a href="javascript:void(0);">...</a></li>';
			$("#paging").append(html);
			var endSize = dataSize - 1;
			html = '<li><a href="javascript:skip(0,' + endSize + ');">' + endSize
					+ '</a></li>';
			$("#paging").append(html);
			html = '<li><a href="javascript:skip(0,' + dataSize + ');">' + dataSize
					+ '</a></li>';
			$("#paging").append(html);

		} else {
			// 尾部长度没有超出三个，不用省略号
			for (var i = endNumber; i > 0; i--) {
				html = '<li><a href="javascript:skip(0,' + dataSize + ');">'
						+ dataSize + '</a></li>';
				$("#paging").append(html);
				dataSize = dataSize - i;
			}
		}
		html = '<li><a href="javascript:skip(2,' + unmSize + ',' + dataSize
				+ ');">&raquo;</a></li>';
		$("#paging").append(html);
	}



	//分页前置配参执行方法
	function skip(type, num, dataSize) {
		if (type == 1) {
			if (num > 1) {
				num = num - 1
			}else{
				return;
			}
			ready(num,10);
		} else if (type == 2) {

			if (num < dataSize) {
				num = num + 1
				var data={'currentPageNum':num};
				ready(num,10);
			}else{
				return;
			}
		} else if (type == 0) {
			ready(num,10);
		} else {

		}

	}

</script>